package com.study.springCustom.spring.registry;

import java.util.HashMap;
import java.util.Map;

public class DefaultSingletonBeanRegistry implements SingletonBeanRegistry {

    private Map<String, Object> singletonObjects = new HashMap<>();

    // 真正的spring在此处使用了三级缓存来解决循环依赖问题，所以单独去管理单例Bean

    @Override
    public void addSingleton(String name, Object bean) {
        // TODO 使用双重坚持锁去实现
        this.singletonObjects.put(name, bean);
    }

    @Override
    public Object getSingleton(String name) {
        return this.singletonObjects.get(name);
    }
}
